<?php

/**
 * SideLabelPie class
 *
 * Plot SideLabelPie
 *
 * @name SideLabelPie
 * @author DiMoN
 * @copyright Dmitry Pavlov
 */

class SideLabelPie extends Chart implements IChart
{
    const CHART_ID = "SideLabelPie",
    CHART_TYPE = 2,
    CHART_NAME = "Круговая диаграмма с выносками";

    /**
     * SideLabelPie constructor
     *
     */
    function __construct()
    {
        $this->isParamsValid();
    }

    /**
     * Gets chart ID specified by the const
     *
     * @return string
     */
    public static function getChartID()
    {
        return self::CHART_ID;
    }

    /**
     * Gets chart Type specified by the const
     *
     * @return int
     */
    public static function getChartType()
    {
        return self::CHART_TYPE;
    }

    /**
     * Gets chart Name specified by the const
     *
     * @return string
     */
    public static function getChartName()
    {
        return self::CHART_NAME;
    }

    /**
     * Checks the validity of the data arrays
     *
     */
    public function isParamsValid()
    {
        if (!isset(parent::$Data2D))
        {
            throw new Exception(self::CHART_ID . ": Data2D array is not set");
        }

        if (!isset(parent::$Labels))
        {
            throw new Exception(self::CHART_ID . ": Labels array is not set");
        }
    }

    /**
     * Plots chart
     *
     * @return string
     */
    public function plot()
    {
        $c = new PieChart(parent::$Width, parent::$Height, parent::$Background);
        $c->setRoundedFrame();
        $c->setPieSize(parent::$Width / 2, parent::$Height / 2, (parent::$Width + parent::$Height) / 8);

        $textBoxObj = $c->addTitle(parent::$Title, parent::$TitleFont , parent::$TitleFontSize , parent::$ColorTitle);
        $textBoxObj->setBackground(parent::$BackgroundTitle1, parent::$BackgroundTitle2, glassEffect());

        $c->set3D();
        $c->setLabelLayout(SideLayout);
        $c->setLabelFormat("{label} - {value} ({percent}%)");

        $t = $c->setLabelStyle(); 
        $t->setBackground(SameAsMainColor, Transparent, glassEffect()); 
        $t->setRoundedCorners(5); 
        
        /**
         * Adding data and labels
         */
        $c->setData(parent::$Data2D, parent::$Labels);

        return parent::saveChart(&$c);
    }
}

?>